/*
 * Copyright (c) 2023 iQi.Co.Ltd. All rights reserved.
 */
 
using IQIGame.Onigao.Framework;
using System.Collections.Generic;
using System.Linq;
using System;
using NetProtocol.Enum;

namespace NetProtocol.POD {

	/// <summary>
	/// 
	/// module : battleLogic
	/// </summary>
	public class BattleStatisticsPOD : IPOD 
    {
        public readonly static Func<BattleStatisticsPOD> FACTORY = () => new BattleStatisticsPOD();
		public static Func<BattleStatisticsPOD> DynamicFactory = FACTORY;
        
		/*-- members --*/
		/// <summary>
        ///  每个单位的输出等
        /// </summary>
        private List<BattleStatisticsUnitPOD> m_units;
		/// <summary>
        ///  击杀的怪物组
        /// </summary>
        private List<int> m_allMonsterTeam;
		
		
        public List<BattleStatisticsUnitPOD> units
        {
            get
            {
                if(m_units == null)
                {
                    m_units = new();
                }
                return m_units;
            }
            private set => m_units = value;
        }
        public List<BattleStatisticsUnitPOD> unsafe_units
        {
        	get => m_units;
        	set => m_units = value;
        }
        public List<int> allMonsterTeam
        {
            get
            {
                if(m_allMonsterTeam == null)
                {
                    m_allMonsterTeam = new();
                }
                return m_allMonsterTeam;
            }
            private set => m_allMonsterTeam = value;
        }
        public List<int> unsafe_allMonsterTeam
        {
        	get => m_allMonsterTeam;
        	set => m_allMonsterTeam = value;
        }
		
		/*-- constructors --*/
		public BattleStatisticsPOD() {}
		public BattleStatisticsPOD(List<BattleStatisticsUnitPOD> units, List<int> allMonsterTeam) {
			this.m_units = units;
			this.m_allMonsterTeam = allMonsterTeam;
		}
	      public void Serial(SOutputStream _out) {
            _out.Write_list_pod(m_units);
            _out.Write_list_int(m_allMonsterTeam); 
        }
        
        public void UnSerial(SInputStream _in) {
            if(!_in.HasRemaining()) return;
            m_units = _in.Read_list_pod<BattleStatisticsUnitPOD>(BattleStatisticsUnitPOD.DynamicFactory);
            if(!_in.HasRemaining()) return;
            m_allMonsterTeam = _in.Read_list_int();
        }
		
		public BattleStatisticsPOD Clone() {
            BattleStatisticsPOD o = DynamicFactory();
            if (m_units != null) {
                o.m_units = m_units.ConvertAll(o => o?.Clone());
            }
            if (m_allMonsterTeam != null) {
                o.m_allMonsterTeam = new (m_allMonsterTeam);
            }
            return o;
        }
        
        public void Clear() {
            m_units = default;
            m_allMonsterTeam = default;
        }
		
        public override string ToString() {
			string str = "";
			str += "BattleStatisticsPOD [";
			str += "units=";
			str += m_units.ToString<BattleStatisticsUnitPOD>();
			str += ", allMonsterTeam=";
			str += m_allMonsterTeam.ToString<int>();
			str += "]";
			return str;
		}
		
	}
}